package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.NightAuditModel;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/5/16 0016.
 * 夜审列表适配器
 */

public class NightAuditListAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<NightAuditModel.PNauStepsListDtoListBean> mList;
    private boolean isShow;
    private HashMap<Integer,Boolean> isRotateMap;//是否完成集合

    public NightAuditListAdapter(Context context, List<NightAuditModel.PNauStepsListDtoListBean> list){
        this.inflater=LayoutInflater.from(context);
        this.mList=list;
        this.isRotateMap = new HashMap<>();
        for(int i=0;i<list.size();i++){
            isRotateMap.put(i,false);
        }
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        NightAuditModel.PNauStepsListDtoListBean text = mList.get(position);
        if(convertView == null) {
            convertView = inflater.inflate(R.layout.night_audit_list_item, null);
            holder = new ViewHolder();
            holder.iv = (ImageView) convertView.findViewById(R.id.ivRotote);
            holder.tv = (TextView) convertView.findViewById(R.id.tv_item);
            convertView.setTag(holder);
        }
        holder= (ViewHolder) convertView.getTag();
        holder.tv.setText(text.getChnDescp());
        if(isShow){
            holder.iv.setVisibility(View.VISIBLE);
            if(isRotateMap.get(position)){
                holder.iv.setImageResource(R.mipmap.xuanzeanniu);
            }else{
                holder.iv.setImageResource(R.mipmap.ic_error);
            }
        }else{
            holder.iv.setVisibility(View.GONE);
        }
        return convertView;
    }

    public void startAnim(boolean isShow){
        this.isShow=isShow;
        this.notifyDataSetChanged();
    }

    /**
     * 请求返回后处理右侧图片
     * @param index 下标
     * @param state 状态(9:成功;other:失败)
     */
    public void setIcon(int index,int state){
        switch (state){
            case 9:
                isRotateMap.put(index,true);
                break;
            default:
                isRotateMap.put(index,false);
                break;
        }
        this.notifyDataSetChanged();
    }

    class ViewHolder{
        TextView tv;
        ImageView iv;
    }
}
